import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table-pagination"; //列表
import actions from "@/actions";

import {
    getSteelProtectionWitnessPageList, //列表
} from "@/api/request.js";

export default {
    props: [
        "dialogVisible", //弹框是否展示
        "dialogTitle", //标题
        "fCompanyid", //标题
    ],
    data() {
        return {
            loading: false,
            visible: "", //弹框展示隐藏
            title: null, //弹框标题
            isLock: false, //取样按钮是否显示
            dialogHeight: null, //弹框高度
            btnShow: true,
            userInfo: {}, //登录用户
            // 列表
            getList: {
                fCompanyid: "",
                page: 1, // 当前页码
                pageSize: 15, // 每页显示条数
                userId: "", // 查询待办或已办时传 列表页查询不传
                modelType: 3, // 0待办 1已办 2查询
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                keyType: "1",
            }, // 列表给后端传参
            table_config: formJs.table_config,
            tableData: [], //列表数据列表
            currentRow: null, //列表详情
            dataFid: null,//fid
            queryCriteriaData: {}, //分页
            // 列表

        };
    },
    components: {
        TableData,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {
                    console.log("fCompanyid", newVal);
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
            // console.log("this.userInfo", this.userInfo);
        }, true);
        this.btnShow = true;

        this.getList = {
            fCompanyid: this.fCompanyid,
            page: 1, // 当前页码
            pageSize: 15, // 每页显示条数
            userId: this.userInfo.id, // 查询待办或已办时传 列表页查询不传
            modelType: 3, // 0待办 1已办 2查询
            startDates: "", // 开始时间
            endDates: "", // 截至时间
            keyType: "1",
        }
        this.yj_searchForm(this.getList) // currentRow
        this.getHeight();

        this.table_config.operation.cols = [
            {
                prop: "fStatus",
                type: "primary",
                handleRow: this.handleRow,
            },
        ];
        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;
            if (rowData == "编辑中") {
                color = "red !important";
            } else if (rowData == "已完成") {
                color = "green !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.7 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 获取列表数据
        yj_searchForm(id) {
            var obj = {
                fCompanyid: this.fCompanyid,
                page: id.page, // 当前页码
                pageSize: 15, // 每页显示条数
                userId: this.userInfo.id, // 查询待办或已办时传 列表页查询不传
                modelType: 3, // 0待办 1已办 2查询
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                keyType: "1",
            };
            this.loading = true;
            var that = this;
            getSteelProtectionWitnessPageList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
        // 点击当前行
        rowChange(val) {
            this.currentRow = val;
            this.dataFid = val.fId;
            return val;
        },

        yj_saveForm() {
            if (this.currentRow != null && this.currentRow != "") {
                this.$emit("getEntrustRow", this.currentRow);
                this.closeDialog();
            } else {
                this.$message.warning("请先选择需要保存的数据");
            }
        },

    },
};